//
//  TWBHomeStatusViewModel.swift
//  weiBo
//
//  Created by 杨雷 on 2016/12/12.
//  Copyright © 2016年 Yang.L. All rights reserved.
//

import UIKit



class TWBHomeStatusViewModel: NSObject {

    lazy var statusList: [TWBStatusViewModel] = [TWBStatusViewModel]()
    
    func loadData(callBack: @escaping (Bool) -> ()) {
        
        TWBNetworkTools.sharedTools.requestStatus { (response, error) in
            
            if error != nil {
                
                print(error!)
                
                callBack(false)
                
                return
            }
            
            let dic = response as! [String: Any]
            
            let statusDicArray = dic["statuses"] as! [[String: Any]]
            
            let modelArray = NSArray.yy_modelArray(with: TWBStatus.self, json: statusDicArray) as! [TWBStatus]
            
            var tempArray = [TWBStatusViewModel]()
            
            for model in modelArray {
                
                let viewModel = TWBStatusViewModel()
                
                viewModel.status = model
                
                tempArray.append(viewModel)
            }
            self.statusList = tempArray
            
            callBack(true)
        }
        
    }
    
}
